/**
 * 行
 * 由四组数字组成
 *
 * 基础数据 是空字符串"" 不是未初始化，也不是null
 */
import RdFeature from "../interface/RdFeature";
import {Buffer} from "../../../../../../../../z_webReactDemoServer/src/main/resources/static/js/standalone/babel";

export default class RdRow extends RdFeature{
    constructor(a,b,c,d){
        super()
        this.buff=new Buffer(13);
        isEmptyOrNumber(a);
        isEmptyOrNumber(b);
        isEmptyOrNumber(c);
        isEmptyOrNumber(d);

        this.list=[a,b,c,d];
        if(d==""){
            this.checkData();
        }
    }

    readFile(n) {
        let res=this.list[n-1];
        if(typeof(res )!=="undefined" ){
            return res;
        }
        return "";
    }
    writeFile(n,data) {
        isEmptyOrNumber(data);
        isEmptyOrNumber(n);
        this.list[n-1]=data;
    }

    isEmptyOrNumber(str) {
        const regex = /^$|^\d+$/; // 匹配空字符串或只包含数字
        return regex.test(str);
    }


    static  toData(rds){

    }

    static dataTo(datas){

    }

    //编码
    encoded(){
        let _this=this;
        if(  this.list.length==0){
            return "";
        }
        let res=""
        for(let i=0;i<_this.list.length;i++){
            if(typeof(this.list[i])!=="undefined" &&this.list[i] !== null){
                let row =this.list[i].toString();
                res+=row+'a'
            }

        }
        return res.substr(0,res.length-1)
    }
    //解码
    decode(words){
        let list =words.split("a")
        for(let l=0;l<list.length;l++){
            this.list[l]=list[l].toString();
        }
        if(this.list[3]==0){
            this.checkData();
        }
    }
}
